#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QThread>
#include <QMutex>
#include <QWaitCondition>


QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    void printOdd();

    void printEven();
signals:
    void updateOdd(int value);
    void updateEven(int value);
public slots:
    void odd(int value);
    void even(int value);

private:
    Ui::MainWindow *ui;
    int count = 1;
    QMutex mutex;
    QWaitCondition oddCondition;
    QWaitCondition evenCondition;
};
#endif // MAINWINDOW_H

class OldThread : public QThread {
    Q_OBJECT
private:
    MainWindow* _p;
public:
    OldThread(MainWindow* p) : _p(p) {}

    void run() override {
        _p->printOdd();
    }
};

class EvenThread : public QThread {
    Q_OBJECT
private:
    MainWindow* _p;
public:
    EvenThread(MainWindow* p) : _p(p) {}

    void run() override {
       _p->printEven();
    }
};
